package cn.marinda.totipotentwar.listener;

import cn.marinda.totipotentwar.TotipotentWar;
import cn.marinda.totipotentwar.global.GameMoveEvent;
import cn.marinda.totipotentwar.runnable.DelayMoveRunnable;
import cn.marinda.totipotentwar.utils.GameUtil;
import cn.marinda.totipotentwar.utils.TimeUtil;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

/**
 * 球员侦听器
 *
 * @author hwj
 * @date 2022/02/11
 */
public class PlayerListener implements Listener {

    /**
     * 在移动游戏
     *
     * @param e e
     */
    @EventHandler
    public void onGameMove(PlayerMoveEvent e){
        if(GameUtil.startFlag){
            GameMoveEvent gameMoveEvent = new GameMoveEvent(e.getPlayer());
            Bukkit.getPluginManager().callEvent(gameMoveEvent);
            if(gameMoveEvent.isCancelled()){
                e.setCancelled(true);
            }else{
                e.setCancelled(false);
            }

        }
    }

    /**
     * deley移动
     *
     * @param e
     */
    @EventHandler
    public void delayMove(GameMoveEvent e){
        //停止该操作！
        if(GameUtil.delayFlag){
            e.setCancelled(false);
        }else{
            e.setCancelled(true);
        }

    }
}
